import urllib.request
import urllib.parse

url = 'http://www.baidu.com/s?wd='

# 模拟浏览器向服务器发送请求

# 请求对象定制，解决反爬
headers = {
    "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
    "cookie": "BIDUPSID=81BF1A3A8A9E3610F1C66D7DB6D97072; PSTM=1693446505; BD_UPN=12314753; BAIDUID=75BFEEDC587D04E0746F10C21EBCE957:FG=1; H_WISE_SIDS_BFESS=60278_60360_60749; H_PS_PSSID=60278_60840; H_WISE_SIDS=60278_60840; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; BAIDUID_BFESS=75BFEEDC587D04E0746F10C21EBCE957:FG=1; BD_CK_SAM=1; delPer=0; BA_HECTOR=ag2h240h2g2h242ga5a1ak8k99ar5a1jfelie1v; ZFY=:Bd8LlZVpkdzaPEo5hkhbIT:AA6hESYzdb811CYuaBwPo:C; BDRCVFR[V3EOV_cRy1C]=mk3SLVN4HKm; baikeVisitId=1129cd25-72cf-4d85-bf4c-b1cee4839025; B64_BOT=1; PSINO=6; H_PS_645EC=1c068bXepu2VwN%2FL4RtnVC%2BVbqnxrm2GLKoz5F62%2FWxHQ9h418ECQuo0ZvATOwyyahvtjNY"
}

# 将周杰伦三个字变成unicode编码的格式
# 我们需要依赖urllib.parse
name = urllib.parse.quote('周杰伦')

url = url + name

request = urllib.request.Request(url=url, headers=headers)
# 模拟服务器发送请求
response = urllib.request.urlopen(request)


content = response.read().decode('utf-8')

print(content)
